/*************************************************************************
 * AUTHOR		 : Chris Hayes
 * STUDENT ID	 : 656960
 * ASSIGNMENT #5 : Multi-Dimensional Array - Tic Tac Toe
 * CLASS		 : CS1A
 * SECTION		 : MW12:30
 * DUE DATE		 : Jun 15, 2011
 *************************************************************************/

#ifndef TICTACHEADER_H_
#define TICTACHEADER_H_

//PREPROCESSOR DIRECTIVES
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>		/**************************************************
						* Added for welcome screen and instructions.
						*  Added to make it easier to format the output in
						*  a separate file as the source file became
						*  unreadable from word wrapping
						**************************************************/

#include <unistd.h>		//<-----------------------------------------------------remove me when compiling @ school!

using namespace std;

/*************************************************************************
 * GLOBAL CONSTANTS													     *
 * ----------------------------------------------------------------------*
 * NUM_ROWS :	The number of rows in the board array					 *
 * NUM_COLS :	The number of columns in the board array				 *
 *************************************************************************/
const int NUM_ROWS = 3;
const int NUM_COLS = 3;

/**************************************************************************
* Output Instruct
* 	This function outputs instructions to the users. There are no input
* 	or output parameters for this function as it only displays text to
* 	the screen.
*
* RETURNS: nothing
* -> Displays the instructions to the user
**************************************************************************/
void OutputInstruct();

/**************************************************************************
 * InitBoard
 * 	This function initializes each spot in the board to a space ' '.
 *
 * RETURNS: Board initialized with all spaces
 *************************************************************************/
void InitBoard(char board[][NUM_COLS]); // tic tac toe board - OUT

/**************************************************************************
 * DisplayBoard
 * 	This function outputs the tic tac toe board including the tokens played
 * 	in the proper format (as described below).
 *
 * 				1		    2		    3
 * 			 [1] [1]  |  [1] [2]  |  [1] [3]
 * 					  |           |
 *  1				  |           |
 *                    |           |
 *          ---------------------------------
 *           [2] [1]  |  [2] [2]  |  [2] [3]
 *                    |           |
 *  2                 |           |
 *                    |           |
 *          ---------------------------------
 *           [3] [1]  |  [3] [2]  |  [3] [3]
 *                    |           |
 *  3                 |           |
 *                    |           |
 *
 *  RETURNS: nothing
 *  -> outputs the current state of the board
 *************************************************************************/
void DisplayBoard(const char board[][NUM_COLS]);// tic tac toe board - OUT

/**************************************************************************
 * GetPlayers
 * 	This function prompts the user and gets the input for the players'
 * 	names.  player1 will always contain the name of the player that is
 * 	using the X token.  player2 will always contain the name of the player
 * 	that is using the O token
 *
 *
 *
 *	RETURNS:
 *		player1 : the name of player1 returned through reference
 *		player2 : the name of player2 returned through reference
 *
 *************************************************************************/
void GetPlayers(string& player1, 	//player X's name - OUT
				string& player2);	//player O's name - OUT

/**************************************************************************
 * GetAndCheckInp
 *
 *************************************************************************/
void GetAndCheckInp(char board[][NUM_COLS],
					char token,
					string player1,
					string player2);

/**************************************************************************
 * SwitchToken
 * 	This function switches the active player.
 * 	It takes in a parameter representing the current player's token
 * 	as a character value (either an X or an O) and returns the opposite.
 * 	For example, if this function receives an X it returns an O.  If it
 * 	receives an O it returns an X.
 *
 * RETURNS: the token opposite of the one in which it receives
 *************************************************************************/
char SwitchToken(char token);	// Current player's token ('X' or 'O') - IN

/**************************************************************************
 * CheckWin
 *	This function checks to see if either player has won.  It should be
 *		run after each player makes a play.
 *
 * RETURNS the character value of the player that won or a value that
 *   indicates a tie.
 *************************************************************************/
char CheckWin(const char board[][NUM_COLS]);

/**************************************************************************
 * OutputWinner
 *
 *************************************************************************/
void OutputWinner(char whoWon,		// Represents the winner or a value
								    // indicating a tied game. 		- IN
				  string player1,	// player X's name				- OUT
				  string player2);	// player O's name				- OUT


/*-----------------------------------------------------------------------*
 * 						ADDITIONAL FUNCTIONS							 *
 * 	These functions were included to add additional features to the game *
 *-----------------------------------------------------------------------*/

/**************************************************************************
 * Welcome
 *
 *************************************************************************/
void Welcome();

/**************************************************************************
 * PlayGame
 *	This function was created because main was becoming quite long due to
 *	 being able to play more than one game.  PlayGame requires the player
 *	 names passed in by value and the scores and ties to be passed by
 *	 reference.  It then calls the functions needed to play 1 complete game
 *	 of TicTacToe.
 *	 	RETURNS
 *	 		score1 : score of player1
 *	 		score2 : score of player2
 *	 		ties   : number of ties
 *
 *************************************************************************/
void PlayGame(string player1,
			  int& score1,
			  string player2,
			  int& score2,
			  int& ties);

/**************************************************************************
 * PlayAgain
 *
 *************************************************************************/
char PlayAgain(string player1,
			   string player2);

/*************************************************************************
 * ScoreBoard
 * 	This function receives the player names, their scores, and the number
 * 	of ties.  It then outputs them in formatted as below.
 *
 * 	-----------------------------------------------------
 *	|   Test Name 1   |   Tie Games   |   Test Name 2   |
 *	-----------------------------------------------------
 *	|        0        |       0       |        0        |
 *	-----------------------------------------------------
 *
 *	RETURNS: nothing
 *	 --> outputs the current score
 *
 *************************************************************************/
void ScoreBoard(string player1,
				int score1,
				string player2,
				int score2,
				int ties);

/**************************************************************************
 * ComputerEasy
 * 	This is currently the only AI being implemented.  It is incredibly
 * 	basic and randomly picks a row and column.  It then checks the board
 * 	to see if that spot is taken already and if so, repicks a new row and
 * 	column.  This function is only used if at least one player is named
 * 	"computer".
 *
 * RETURNS:
 *  it returns a valid row and column to the GetAndCheckInp function.
 *
 *************************************************************************/
void ComputerEasy(int& row,
				  int& col,
				  const char board[][NUM_COLS]);

/**************************************************************************
 * SwitchPlayers
 * 	This function askes the players if they would like to switch tokens.
 * 	It is ran after every game is played.
 *
 *
 * RETURNS:
 * 	 If the answer is yes, then the names and scores of player1 and player2
 * 	 are swapped with each other.  If the answer is no, nothing is swapped.
 *
 *************************************************************************/
void SwitchPlayers(string& player1,	//Name of player one  -CALC & OUT
				   int& score1,		//Score of player one -CALC & OUT
				   string& player2,	//Name of player two  -CALC & OUT
				   int& score2);	//Score of player two -CALC & OUT

#endif /* TICTACHEADER_H_ */
